﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Controls;
namespace WPFExcelReport
{

    public partial class TRVRULES
    {
        #region ==TMU===========
        public static readonly DependencyProperty TMUProperty = DependencyProperty.Register("TMU",
        typeof(string), typeof(TRVRULES),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnTMUChanged));
        public string TMU
        {
            get
            {
                return (string)GetValue(TMUProperty);
            }
            set
            {
                SetValue(TMUProperty, value);
                OnTMUChg(value);
            }
        }
        private static void OnTMUChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TRVRULES;
            if (src != null)
            {
                src.TMU = (string)e.NewValue;
            }
        }
        public virtual void OnTMUChg(string value)
        {
            if (dwMaster == null)
                return;
            TMV.R01DES = TMU;
        }
        #endregion
        public TRVRULES()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            InitializeComponent();
        }
        public override void Reset()
        {

            base.Reset();

        }
        private void btnResetP_Click(object sender, RoutedEventArgs e)
        {
            Reset();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                TMU = "";
            }
            else
            {
                TMU = Helpers.Helper.Left(TMV.R01DES.PadRight(2), 2);
            }
            CHKFLOW();
        }
        public void CHKFLOW()
        {
            if (dwMaster == null)
                return;
            string ARTSTAGE = dwMaster["ARTSTAGE"].ToString();
            FLOW = "";
            string GSFACH = "";
            switch (app.company)
            {
                case "YGR":

                    GSFACH = dwMaster["P2"].ToString();
                    if (System.Convert.ToDouble(GSFACH) > 1)
                    {
                        FLOW = "HM000001";
                    }
                    else
                    {
                        FLOW = "HM000001";
                    }
                    break;
                default:
                case "UBT":

                    GSFACH = dwMaster["P2"].ToString();
                    if (System.Convert.ToDouble(GSFACH) > 1)
                    {
                        FLOW = "HM000001";
                    }
                    else
                    {
                        FLOW = "HM000001";
                    }
                    break;
            }
        }
        public override void OnR01Chg()
        {
            base.OnR01Chg(); 
            switch (app.company)
            {
                #region=YGR
                case "YGR":

                    switch (ARTSTAGE)
                    {
                        case "S":
                            break;
                        case "T":
                            break;
                        case "X":
                            break;
                        case "R": 
                            TMV.SUBRESETRVR01();
                            break;
                    }
                    break;

                    #endregion

            }

        }
        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (!IsManage)
            {
                VICC_WFEVENTS.SVWF.CSR(RUNID);
            }
            else
            {
                TMV.TBCSRules = null;
            }
            base.ManageCommand(sender, e);
        }

    }
}
